[deps]

[vars]
filesize=2826473
sha512=d7c5e54b6d4d8b9211f0006ca8786f7609d180cc1aaebf4f25e7e35e12959779cf66447359a602daed625621ca32b0d910d67aef3eb8b6fdc3c373819a88faa1

[mirrors]
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz

[build]
patch -p1 < "$K"/ncurses-cross-include.patch
patch -p1 < "$K"/ncurses-gcc5.patch
# prevent pulling in the hosts termcap.h which may conflict - plus it doesn't
# define everything ncurses expects from its own termcap.h
ln -s termcap.h include/termcap_internal.h
t=ncurses/tinfo
for culprit in progs/tset.c $t/lib_baudrate.c $t/lib_cur_term.c $t/lib_termcap.c $t/lib_tgoto.c $t/lib_tputs.c ; do
	sed -i 's@termcap\.h@termcap_internal.h@' $culprit
done
#the fallbacks file is needed to have no external dependencies.
#it is created using:
#ncurses/tinfo/MKfallback.sh /usr/share/terminfo/ /etc/termcap tic linux vt100 term xterm-256color > fallback.c
#on a machine that has those files.
cp "$K"/ncurses-fallback.c ncurses/fallback.c

[ -n "$CROSS_COMPILE" ] && xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/')"

# that </dev/ptmx is to fix an insanely stupid test for poll which
# needs to block on fd 1 (which they assume to be a tty).
# -fPIC is needed to unbreak lto, as ncurses builds only some .o's with it
CFLAGS="-D_GNU_SOURCE $optcflags -fPIC" ./configure -C \
   --with-normal --without-tests \
   --enable-widec \
   --with-shared \
   --enable-sigwinch --with-fallbacks="linux vt100 xterm xterm256-color" \
   --prefix="$butch_prefix" --includedir="$butch_prefix"/include --mandir="$butch_prefix"/share/man \
   --disable-nls --without-dlsym \
   --without-cxx-binding $xconfflags </dev/ptmx
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

dest="$butch_install_dir""$butch_prefix"
(
cd "$dest"/lib/
for i in  lib*.* ; do
	l=$(echo $i | awk '{ p = index($1, "."); if(substr($1, p-1, 1) == "w") { a = substr($1, 0, p -2);} else { a = substr($1, 0, p -4) "_g"; } ; b = substr ($1, p); $0 = a b; print; }')
	ln -s "$i" "$l"
done
# create empty libterminfo.a and symlinks to libcurses.a,so to be compatible
# with recipes written for netbsd-curses
"$CROSS_COMPILE"ar rc libterminfo.a
ln -sf libncurses.a libcurses.a
ln -sf libncurses.so libcurses.so
)
